package admission.ecnu.mainservlet;

import java.util.Enumeration;

import org.json.JSONException;
import org.json.JSONObject;

import admission.ecnu.interfaces.IRequestProcessor;



public class JsonRequestProcessor implements IRequestProcessor {

	public void processContext(RnsContext context) {

		JSONObject jsonRequest = new JSONObject();

		Enumeration<?> enumeration = context.getRequest().getParameterNames();

		while (enumeration.hasMoreElements()) {

			String parameterName = enumeration.nextElement().toString();

			if (!parameterName.toLowerCase().equals("method")
					&& !parameterName.toLowerCase().equals("output")
					&& !parameterName.toLowerCase().equals("apikey")) {

				String parameterValue = context.getRequest().getParameter(parameterName);

				try {
					jsonRequest.put(parameterName, parameterValue);
				} catch (JSONException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
		context.setJsonRequestObject(jsonRequest);
	}

}
